//
// Created by Zhiqiang dai on 2020/8/8.
//

/**
 *  echatim sdk 动态库桥接接口.
 *  用法: TODO
 *     C/C++(windows):
 *
 *     C/C++(linux,mac):
 *        void *handle = dlopen(SDK_DLL_PATH, RTLD_NOW);
 *        sdkInit = (pfunc_sdk_init) dlsym(handle, "sdk_init");
 *        sdkSetApiListener = (pfunc_sdk_set_api_listener) dlsym(handle, "sdk_set_api_listener");
 *        sdkInvokeApi = (pfunc_sdk_invoke_api) dlsym(handle, "sdk_invoke_api");
 *
 * */

#ifndef ECHATIMSDK_H
#define ECHATIMSDK_H

#ifdef __cplusplus
extern "C"
{
#endif

#ifdef WINDOW_VISUAL_STUDIO
#define DLL_EXPORT_SPEC _declspec(dllexport)
#else
#define DLL_EXPORT_SPEC
#endif


typedef void(*pfunc_init_cb)(int ret, const char *err_msg);
typedef void(*pfunc_listener_cb)(const char *method, int argc, const char *argv[]);
typedef void(*pfunc_api_cb)(unsigned long call_id, const char *api_method, const char *response);

typedef long HANDLE_ID_TYPE;
typedef void(*pfunc_upload_cb)(unsigned long handle_id, const char *method, int argc, const char *argv[]);


// sdk DLL 方法签名
typedef void (*pfunc_sdk_init)(const char *json_config, pfunc_init_cb init_cb, pfunc_listener_cb listener_cb);
typedef void (*pfunc_sdk_set_api_listener)(pfunc_api_cb api_cb);
typedef void (*pfunc_sdk_invoke_api)(unsigned long call_id, const char *method, const char *json_params);

// fileserver DLL 方法签名
typedef HANDLE_ID_TYPE (*pfunc_sdk_fileserver_instance)();
typedef void (*pfunc_sdk_fileserver_init)(HANDLE_ID_TYPE handle_id, const char *json_upload_config);
typedef void (*pfunc_sdk_fileserver_set_upload_listener)(HANDLE_ID_TYPE handle_id, pfunc_upload_cb upload_cb);
typedef void (*pfunc_sdk_fileserver_invoke_upload)(HANDLE_ID_TYPE handle_id, const char *filepath, int sub_thread);
typedef void (*pfunc_sdk_fileserver_release)(HANDLE_ID_TYPE handle_id);

// 以下是对外暴露的DLL方法
DLL_EXPORT_SPEC void sdk_init(const char *json_config, pfunc_init_cb init_cb, pfunc_listener_cb listener_cb);
DLL_EXPORT_SPEC void sdk_set_api_listener(pfunc_api_cb api_cb);
DLL_EXPORT_SPEC void sdk_invoke_api(unsigned long call_id, const char *method, const char *json_params);
DLL_EXPORT_SPEC void sdk_release();

// 以下是fileserver对外暴露的DLL方法
DLL_EXPORT_SPEC HANDLE_ID_TYPE sdk_fileserver_instance();
DLL_EXPORT_SPEC void sdk_fileserver_init(HANDLE_ID_TYPE handle_id, const char *json_upload_config);
DLL_EXPORT_SPEC void sdk_fileserver_set_upload_listener(HANDLE_ID_TYPE handle_id, pfunc_upload_cb upload_cb);
DLL_EXPORT_SPEC void sdk_fileserver_invoke_upload(HANDLE_ID_TYPE handle_id, const char *filepath, int sub_thread);
DLL_EXPORT_SPEC void sdk_fileserver_release(HANDLE_ID_TYPE handle_id);



#ifdef __cplusplus
}
#endif


#endif // ECHATIMSDK_H
